package com.foo.ui_demo_widget;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.foo.ui_demo_widget.adapter.ClassroomBuildingAdapter;
import com.foo.ui_demo_widget.pojo.ClassroomBuilding;

import java.util.ArrayList;

public class ListView4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view2);
        ArrayList<ClassroomBuilding> classroomBuildings = new ArrayList<>();
        classroomBuildings.add(new ClassroomBuilding("文友楼","510","多媒体"));
        classroomBuildings.add(new ClassroomBuilding("香远楼","618","普通"));
        classroomBuildings.add(new ClassroomBuilding("实验楼","605","计算机实验室"));
        classroomBuildings.add(new ClassroomBuilding("文友楼","619","多媒体"));
        ListView lv = findViewById(R.id.lv_contact);
        lv.setAdapter(new ClassroomBuildingAdapter(this, classroomBuildings));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ClassroomBuilding item = (ClassroomBuilding) lv.getItemAtPosition(i);
                Toast.makeText(ListView4Activity.this,item.toString(),Toast.LENGTH_SHORT).show();
            }
        });
    }
}